<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>添加列表 </el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card class="box-card">
      <!-- 查询区域 -->
      <el-row style="margin-bottom: 15px">
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表单区域 -->
      <el-table :data="orderList" stripe border highlight-current-row>
        <el-table-column type="index" label="#" width="80" align="center">
        </el-table-column>
        <el-table-column prop="order_number" label="订单列表" align="center">
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="180"
          align="center"
        >
        </el-table-column>
        <el-table-column label="是否付款" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay === '1'">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" align="center">
        </el-table-column>
        <el-table-column label="下单时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.create_time | formatDate }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            {{ scope.row.order_id }}
            <el-button
              type="primary"
              icon="el-icon-edit"
              @click="showBox"
            ></el-button>
            <el-button
              type="success"
              icon="iconfont icon-dingwei"
              @click="ShowKuiadi"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 5, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>
    <!-- 显示修改地址的弹框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="addressVisible"
      @close="addressClosed"
    >
      <el-form :model="addressForm" :rules="addressRules" ref="addressFormRef">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :options="cityData"
            :props="{
              expandTrigger: 'hover',
              value: 'value',
              label: 'label',
              children: 'children',
            }"
            style="width: 70%"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input
            v-model="addressForm.address2"
            style="width: 70%"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 显示快递的弹框 -->
    <el-dialog title="快递信息" :visible.sync="kuaidiVisible">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in kuaidiInfo"
          :key="index"
          :timestamp="activity.ftime"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
import cityData from "./citydata";
import kuaidiInfo from "./kuiadiInfo";
import { reqOrderList } from "../../api";
export default {
  data() {
    return {
      // 订单列表数据
      orderList: [],
      // 查询信息
      queryInfo: {
        // 当前是第几页，
        pagenum: 1,
        // 每页几条数据
        pagesize: 8,
      },
      // 一共多少条数据
      total: 5,
      // 是否显示地址弹窗
      addressVisible: false,
      // 地址数据信息
      cityData,
      // 修改地址的表单信息
      addressForm: {
        // 级联选择器选中的值
        address1: [],
        address2: "",
      },
      // 修改地址的规则
      addressRules: {
        address1: [
          { required: true, message: "请选择省市区/县", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      // 是否显示快递信息的弹窗
      kuaidiVisible: false,
      // 快递物流的信息数据
      kuaidiInfo: kuaidiInfo.data,
    };
  },
  mounted() {
    this.getOrderList();
  },
  methods: {
    // 获取订单列表
    async getOrderList() {
      const result = await reqOrderList(this.queryInfo);
      if (result.meta.status != 200)
        return this.$message.error(result.meta.msg);
      this.orderList = result.data.goods;
      this.total = result.data.total;
    },
    // 当pagesize发生变化调用的函数
    handleSizeChange(newPagesize) {
      this.queryInfo.pagesize = newPagesize;
      this.getOrderList();
    },
    // 当pagenum发生变化调用的函数
    handleCurrentChange(newPagenum) {
      this.queryInfo.pagenum = newPagenum;
      this.getOrderList();
    },
    // 点击按钮，显示修改地址弹框
    showBox() {
      this.addressVisible = true;
    },
    // 级联选择器框中发生变化没回触发这个函数
    handleChange() {
      console.log(this.addressForm);
    },
    //关闭地址弹窗会触发的函数
    addressClosed() {
      this.$refs.addressFormRef.resetFields();
    },
    // 点击显示快递信息的按钮所触发的函数
    ShowKuiadi() {
      this.kuaidiVisible = true;
      // const result = await reqKuaiDiInfo();
      // console.log(result);
    },
  },
};
</script>

<style lang="less" scoped>
</style>
